/*
 *  Copyright (C) 2011 glauco
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.balisunrise.swing.commons;

import java.util.ArrayList;
import java.util.List;
import javax.swing.JLabel;
import org.balisunrise.common.Action;
import org.balisunrise.common.EntityFieldType;
import org.balisunrise.common.Event;
import org.balisunrise.common.abstracts.AbstractFieldComponent;
import org.balisunrise.common.listeners.FieldActionListener;

/**
 *
 * @author glauco
 */
public class FieldAction extends AbstractFieldComponent
        implements org.balisunrise.common.FieldAction<JLabel>{

    private JLabel visualRepresentation;
    private Action action;
    private List<FieldActionListener> listeners;

    public FieldAction(Action action) {
        listeners = new ArrayList<FieldActionListener>();
        this.action = action;
    }

    public void setVisualRepresentation(JLabel visualRepresentation) {
        this.visualRepresentation = visualRepresentation;
    }

    @Override
    public boolean requestFocus() {
        return false;
    }

    @Override
    public JLabel getVisualRepresentation() {
        return visualRepresentation;
    }

    @Override
    public EntityFieldType getEntityFieldType() {
        return EntityFieldType.ACTION;
    }

    @Override
    public boolean setEnabled(boolean enabled) {
        return false;
    }

    @Override
    public void perform(Event event) {
        action.perform(event);
    }

    @Override
    public void addFieldActionListener(FieldActionListener fl) {
        listeners.add(fl);
    }

    @Override
    public boolean removeFieldActionListener(FieldActionListener fl) {
        return listeners.remove(fl);
    }

    @Override
    public FieldActionListener[] getFieldActionListeners() {
        return listeners.toArray(new FieldActionListener[]{});
    }
}
